package com.yjm.test.Spring5.ch2;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.GenericApplicationContext;

@ComponentScan("com.yjm.test.Spring5")
@Configuration
public class HelloWorldConfiguration {
	
	@Bean
	public MessageProvider provider() {
		return new HelloWordMessageProvider();
	}

	@Bean
	public MessageRenderer renderer() {
		MessageRenderer renderer = new StandardOutMessageRenderer();
		renderer.setMessageProvider(provider());
		return renderer;
	}
	
	public static void main(String... args) {
		GenericApplicationContext ctx = new AnnotationConfigApplicationContext(HelloWorldConfiguration.class);
		// dependency pull DL依赖拉取   contextualized dependency lookup CDL 上下文依赖查找
		MessageRenderer mr  = (MessageRenderer) ctx.getBean("renderer");
		mr.render();
		
		ctx.close();
	}
}
